package com.yunxi.service.dubboService.impl.sto;

import com.alibaba.cloud.context.utils.StringUtils;
import com.github.pagehelper.PageInfo;
import com.yunxi.service.localService.sto.FinanceReportService;
import com.yunxi.sto.pojo.*;
import com.yunxi.sto.service.FinanceReportDubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

/**
 * <p>
 * 金融业务报表 服务实现类
 * </p>
 *
 * @author caoYong
 * @since 2019-10-09
 */
public class FinanceReportDubboServiceImpl implements FinanceReportDubboService {


    @Autowired
    @Qualifier(value = "financeReportServiceImpl")
    FinanceReportService financeReportService;


    /**
     * 业务分析
     * @param businessCensusVO
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<BusinessCensusVO> businessCensus(BusinessCensusVO businessCensusVO, Integer pageNum, Integer pageSize) throws Exception {
        String partnerCodes = businessCensusVO.getPartnerCodes();//逗号拼接的金融公司代码
        String provinceCodes = businessCensusVO.getProvinceCodes();//逗号拼接的省代码
        if(StringUtils.isNotEmpty(partnerCodes)){
            String[] split = partnerCodes.split(",");
            List<String> list1 = Arrays.asList(split);
            businessCensusVO.setPartnerCodeList(list1);
        }
        if(StringUtils.isNotEmpty(provinceCodes)){
            String[] split = provinceCodes.split(",");
            List<String> list2 = Arrays.asList(split);
            businessCensusVO.setProvinceCodeList(list2);
        }
        return financeReportService.businessCensus(businessCensusVO,pageNum,pageSize);
    }

    @Override
    public List<BusinessCensusVO> businessCensusMonth(BusinessCensusVO businessCensusVO, Integer pageNum, Integer pageSize) {
        if (StringUtils.isEmpty(businessCensusVO.getYear())){
            Calendar date = Calendar.getInstance();
            String year = String.valueOf(date.get(Calendar.YEAR));
            businessCensusVO.setYear(year);
        }
        String partnerCodes = businessCensusVO.getPartnerCodes();//逗号拼接的金融公司代码
        String provinceCodes = businessCensusVO.getProvinceCodes();//逗号拼接的省代码
        if(StringUtils.isNotEmpty(partnerCodes)){
            String[] split = partnerCodes.split(",");
            List<String> list1 = Arrays.asList(split);
            businessCensusVO.setPartnerCodeList(list1);
        }
        if(StringUtils.isNotEmpty(provinceCodes)){
            String[] split = provinceCodes.split(",");
            List<String> list2 = Arrays.asList(split);
            businessCensusVO.setProvinceCodeList(list2);
        }
        return financeReportService.businessCensusMonth(businessCensusVO,pageNum,pageSize);
    }

    @Override
    public PageInfo<ExpCarVO> expCarLeaseTime(ExpCarVO expCarVO, Integer pageNum, Integer pageSize) {
        String provinceCodes = expCarVO.getProvinceCodes();//逗号拼接的省代码
        if(StringUtils.isNotEmpty(provinceCodes)){
            String[] split = provinceCodes.split(",");
            List<String> list2 = Arrays.asList(split);
            expCarVO.setProvinceCodeList(list2);
        }
        return financeReportService.expCarLeaseTime(expCarVO,pageNum,pageSize);
    }

    @Override
    public PageInfo<CreditReportVO> creditRepotr(CreditReportVO creditReportVO, Integer pageNum, Integer pageSize) {
        String partnerCodes = creditReportVO.getPartnerCodes();//逗号拼接的金融公司代码
        if(StringUtils.isNotEmpty(partnerCodes)){
            String[] split = partnerCodes.split(",");
            List<String> list1 = Arrays.asList(split);
            creditReportVO.setPartnerCodeList(list1);
        }
        return financeReportService.creditRepotr(creditReportVO,pageNum,pageSize);
    }

    @Override
    public PageInfo<ExpCarFreeVO> expCarFree(ExpCarFreeVO expCarFreeVO, Integer pageNum, Integer pageSize) {
        String provinceCodes = expCarFreeVO.getProvinceCodes();//逗号拼接的省代码
        if(StringUtils.isNotEmpty(provinceCodes)){
            String[] split = provinceCodes.split(",");
            List<String> list2 = Arrays.asList(split);
            expCarFreeVO.setProvinceCodeList(list2);
        }
        return financeReportService.expCarFree(expCarFreeVO,pageNum,pageSize);
    }

   @Override
   public PageInfo<ProductAnalyzeVO> productAnalyze(ProductAnalyzeVO productAnalyzeVO, Integer pageNum, Integer pageSize) throws Exception {
        if (StringUtils.isEmpty(productAnalyzeVO.getBusinessType())) productAnalyzeVO.setBusinessType("1");
        if (StringUtils.isEmpty(productAnalyzeVO.getPartnerCodes())) throw new Exception("请选择金融机构");
       String partnerCodes = productAnalyzeVO.getPartnerCodes();//逗号拼接的金融公司代码
       if(StringUtils.isNotEmpty(partnerCodes)){
           String[] split = partnerCodes.split(",");
           List<String> list1 = Arrays.asList(split);
           productAnalyzeVO.setPartnerCodeList(list1);
       }
      return financeReportService.productAnalyze(productAnalyzeVO,pageNum,pageSize);
   }

   @Override
   public List<BusinessCensusVO> businessCensusList(BusinessCensusVO businessCensusVO) {
       String partnerCodes = businessCensusVO.getPartnerCodes();//逗号拼接的金融公司代码
       String provinceCodes = businessCensusVO.getProvinceCodes();//逗号拼接的省代码
       if(StringUtils.isNotEmpty(partnerCodes)){
           String[] split = partnerCodes.split(",");
           List<String> list1 = Arrays.asList(split);
           businessCensusVO.setPartnerCodeList(list1);
       }
       if(StringUtils.isNotEmpty(provinceCodes)){
           String[] split = provinceCodes.split(",");
           List<String> list2 = Arrays.asList(split);
           businessCensusVO.setProvinceCodeList(list2);
       }
       return financeReportService.businessCensusList(businessCensusVO);
   }

    @Override
    public List<CreditReportVO> creditRepotrList(CreditReportVO creditReportVO) {
        String partnerCodes = creditReportVO.getPartnerCodes();//逗号拼接的金融公司代码
        if(StringUtils.isNotEmpty(partnerCodes)){
            String[] split = partnerCodes.split(",");
            List<String> list1 = Arrays.asList(split);
            creditReportVO.setPartnerCodeList(list1);
        }
        return financeReportService.creditRepotrList(creditReportVO);
    }

    @Override
    public List<ExpCarVO> expCarLeaseTimeList(ExpCarVO expCarVO) {
        String provinceCodes = expCarVO.getProvinceCodes();//逗号拼接的省代码
        if(StringUtils.isNotEmpty(provinceCodes)){
            String[] split = provinceCodes.split(",");
            List<String> list2 = Arrays.asList(split);
            expCarVO.setProvinceCodeList(list2);
        }
        return financeReportService.expCarLeaseTimeList(expCarVO);
    }

    @Override
    public List<ExpCarFreeVO> expCarFreeList(ExpCarFreeVO expCarFreeVO) {
        String provinceCodes = expCarFreeVO.getProvinceCodes();//逗号拼接的省代码
        if(StringUtils.isNotEmpty(provinceCodes)){
            String[] split = provinceCodes.split(",");
            List<String> list2 = Arrays.asList(split);
            expCarFreeVO.setProvinceCodeList(list2);
        }
        return financeReportService.expCarFreeList(expCarFreeVO);
    }

    @Override
    public List<ProductAnalyzeVO> productAnalyzeList(ProductAnalyzeVO productAnalyzeVO) throws Exception {
        if (StringUtils.isEmpty(productAnalyzeVO.getBusinessType())) throw new Exception("类型为空");
        if (StringUtils.isEmpty(productAnalyzeVO.getPartnerCodes())) throw new Exception("请选择金融机构");
        String partnerCodes = productAnalyzeVO.getPartnerCodes();//逗号拼接的金融公司代码
        if(StringUtils.isNotEmpty(partnerCodes)){
            String[] split = partnerCodes.split(",");
            List<String> list1 = Arrays.asList(split);
            productAnalyzeVO.setPartnerCodeList(list1);
        }
        return financeReportService.productAnalyzeList(productAnalyzeVO);
    }
}
